package com.push.notifications;

import com.push.cache.ImageLoader;
import com.push.notifications.R;
import java.util.List;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

 public class historyAdapterListView extends ArrayAdapter<historyItem> {
    
    private  final List<historyItem> listMesage;
    private   Activity context;
    boolean checkAll_flag = false;
    boolean checkItem_flag = false;
    private historyItem model_just_click;
    private View curCheckBoxView; 
    public ImageLoader imageLoader2;
    
    
    public historyAdapterListView(Activity context, List<historyItem> listMesage) {
        super(context, R.layout.list_mesage, listMesage);
        this.context = context;
        this.listMesage = listMesage;
        imageLoader2 =new ImageLoader(this.context.getApplicationContext());
    }
    
    public List<historyItem> getListMessage()
    {
    	return listMesage;
    }
    static class View_Holder {
        protected TextView text_name;
        protected TextView text_message;
        protected TextView text_time;
        protected ImageView image_descrip;
        protected int post;
        
    }
    
    public void setJustClick(historyItem model){
    	model_just_click = model;
    }
    
    public historyItem getJustClick(){
    	return model_just_click;
    }
    
    public void updateStatus(historyItem model)
    {
    	View_Holder View_Holder = null;
    	View_Holder = new View_Holder();
    	//View_Holder.checkbox = (CheckBox) curCheckBoxView.findViewById(R.id.checkBox1);    
       // View_Holder.checkbox.setChecked(model.isSelected());
        listMesage.set(model.getPos(), model);
        
    }
    
    public String trimText(String sSource)
    {
    	if(sSource.length() < 80)
    		return sSource;
    	String sResult = sSource.substring(0, 80) ;
    	
    	sResult = sResult + "...";
    	return sResult;
    }
    @Override
    public View getView( int position, View convertView, ViewGroup parent) {
        
         View_Holder View_Holder = null;
        
        if (convertView == null) {
            LayoutInflater inflator = context.getLayoutInflater();
            convertView = inflator.inflate(R.layout.list_mesage, null);
            
            convertView.setClickable(true);
            //convertView.setOnClickListener(((HistoryActivity)context).myClickListener);
            
            View_Holder = new View_Holder();
            historyItem item =listMesage.get(position);
            
            View_Holder.text_message = (TextView) convertView.findViewById(R.id.textView1);
            View_Holder.text_message.setText(trimText(item.message));
            View_Holder.image_descrip = (ImageView) convertView.findViewById(R.id.quickImage);
            //imageLoader2.DisplayImage(item.s_image, View_Holder.image_descrip);
            /// => can link anh
            ///

            convertView.setTag(View_Holder);
            convertView.setTag(R.id.textView1, View_Holder.text_message);
            //convertView.setTag(R.id.textView2, View_Holder.text_time);
            
            } else {
            View_Holder = (View_Holder) convertView.getTag();
        }
        historyItem model2 =listMesage.get(position);
        View_Holder.post=position;
       // View_Holder.text.setText(model2.name);
        //View_Holder.text_name.setText(model2.name) ;
        View_Holder.text_message.setText(trimText(model2.message)) ;
       // View_Holder.text_time.setText(model2.getDate()) ;        
        return convertView;
    }
    
} 
